<?php

namespace app\common\service;
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\OssClient;
use OSS\Core\OssException;

class UpService{

	public static $accessKeyId     = "LTAI4FsfJWDPj2GxeXL1GCBQ";
	public static $accessKeySecret = "mHr4VvLMsoJdwccJac1yljW4MXuSzt";
	public static $endpoint        = "http://oss-cn-hangzhou.aliyuncs.com";
	public static $bucket          = "pic-ky";

	public static function Upp($file){

		$ossClient = new OssClient(self::$accessKeyId, self::$accessKeySecret, self::$endpoint);

    	$res = $ossClient->uploadFile(self::$bucket, 'ky/'.md5($file).'.jpg', $file);
    	return $res['info']['url'];
	}

	public static function cj(){
		$ossClient = new OssClient(self::$accessKeyId, self::$accessKeySecret, self::$endpoint);
	    // 设置存储空间的存储类型为低频访问类型，默认是标准类型。
	    $options = array(
	        OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_IA
	    );
	    // 设置存储空间的权限为公共读，默认是私有读写。
   		$ossClient->createBucket(self::$bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ, $options);
	}
}
